<template>
  <div class="talk">
    <button @click="getLoveTk()">点击获取一句土味情话</button>
    <ul>
      <li v-for="tk in talkList" :key="tk.id">{{ tk.content }}</li>
    </ul>
  </div>
</template>

<script setup lang="ts" name="LoveTalk">
import { useloveTalkStore } from "@/store/loveTalk";
import { storeToRefs } from "pinia";

const talkStore = useloveTalkStore();
const { talkList } = storeToRefs(talkStore);

talkStore.$subscribe((mutate, state) => {
  console.log("talkStore里面的数据发生了变化", mutate, state);
  localStorage.setItem("talkList", JSON.stringify(state.talkList));
});

function getLoveTk() {
  talkStore.getATalk();
}
</script>

<style scoped>
.talk {
  background-color: pink;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}
</style>
